import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/Index.vue'
import {getToken} from '../utils/auth.js'

Vue.use(VueRouter)

const routes = [
  {
    path: '/management',
    name: '账户管理',
    meta: {
      navShow: true,
      title: '纵信快手项目管理'
  },
  component: () => import('../views/management/management.vue')
  },
  {
    path: '/team',
    name: '团队',
    meta: {
      navShow: true,
      title: '纵信快手项目管理'
  },
  component: () => import('../views/team/team.vue')
  },
  {
    path: '/avertisement',
    name: '广告',
    meta: {
      navShow: true,
      title: '纵信快手项目管理'
  },
    component: () => import('../views/project/advertisement.vue')
  },
  {
    path: '/login',
    name: '登录',
    meta: {
      navShow: false,
      title: '纵信快手项目管理'
  },
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/',
    name: 'index',
    meta: {
      navShow: true,
      title: '纵信快手项目管理',
      usertoken:getToken('vue_admin_template_token')
  },
    component: index
  },{
    path: '/details',
    name: 'details',
    meta: {
      navShow: true,
      title: '纵信快手项目管理'
  },
  component: () => import('../views/project/details.vue')
  }
]

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
  if(getToken('vue_admin_template_token')){
    //登陆
    next()
  }else{
    //没有登陆
    if(to.path=='/login'){
      next()
    }else{
      next('/login')
    }
  }
  // if (to.path === '/login') {
  //   next()
  //   // var tokenStr = window.sessionStorage.getItem('token')
  // }
  // if (!tokenStr) {
  //   next()
  // } else {
  //   next('/login')
  // }
  
})
export default router
